package streaming

import java.util.{Date, Properties}

import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
import org.apache.kafka.common.serialization.StringSerializer

object Producer {
  def main(args: Array[String]): Unit = {

    //定义配置文件对象
    val properties = new Properties
    properties.setProperty("bootstrap.servers", "master:9092,node1:9092,node2:9092") //kafka连接地址
    properties.put("key.serializer", classOf[StringSerializer])
    properties.put("value.serializer", classOf[StringSerializer])

    //创建连接   创建生产者
    val producer = new KafkaProducer[String, String](properties)

    //以时间戳作为key
    val key = new Date().getTime.toString

    val value = "python"

    //构建消息对象
    val record = new ProducerRecord[String, String]("topic3", key, value)

    //发送消息
    producer.send(record)
    //关闭连接
    producer.close()


  }
}
